/*
 *  The MIT License
 * 
 *  Copyright 2011 Jeremy Heng | Jaybles | Vxtherael.
 * 
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 * 
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 * 
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */

package com.codesinverse.neuralnetworkstests.perceptronstests.informaltests;

import com.codesinverse.neuralnetworks.perceptrons.HiddenPerceptron;
import com.codesinverse.neuralnetworks.perceptrons.InputPerceptron;
import com.codesinverse.neuralnetworks.perceptrons.OutputPerceptron;
import com.codesinverse.neuralnetworks.perceptrons.Perceptron;

/**
 *
 * @author Jeremy Heng | Jaybles | Vxtherael
 */
public class InformalTest1 {
    
    public void nodeTest() {
        InputPerceptron[] input = new InputPerceptron[4];
        for (int i = 0; i < input.length; i++) {
            input[i] = new InputPerceptron();
        }

        HiddenPerceptron[] hidden = new HiddenPerceptron[3];
        for (int i = 0; i < hidden.length; i++) {
            hidden[i] = new HiddenPerceptron();
        }

        OutputPerceptron[] output = new OutputPerceptron[5];
        for (int i = 0; i < output.length; i++) {
            output[i] = new OutputPerceptron();
        }

        hidden[0].setThreshold(2);
        hidden[1].setThreshold(1);
        hidden[2].setThreshold(2);

        hidden[0].addInputNode(input[0], 1);
        hidden[0].addInputNode(input[3], 1);

        hidden[1].addInputNode(input[1], 1);
        hidden[1].addInputNode(input[2], 1);

        hidden[2].addInputNode(input[2], 1);

        output[0].addInputNode(hidden[0], 1);

        output[1].addInputNode(hidden[1], 1);

        output[2].addInputNode(hidden[0], 1);
        output[2].addInputNode(hidden[2], 1);

        output[3].addInputNode(hidden[1], 1);

        output[4].addInputNode(hidden[2], 1);

        System.out.println(output[2] + "\n");
        
        input[0].setEmit(false); input[1].setEmit(false); input[2].setEmit(false); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(false); input[2].setEmit(false); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(false); input[2].setEmit(true); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(false); input[2].setEmit(true); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(true); input[2].setEmit(false); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(true); input[2].setEmit(false); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(true); input[2].setEmit(true); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(false); input[1].setEmit(true); input[2].setEmit(true); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(false); input[2].setEmit(false); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(false); input[2].setEmit(false); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(false); input[2].setEmit(true); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(false); input[2].setEmit(true); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(true); input[2].setEmit(false); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(true); input[2].setEmit(false); input[3].setEmit(true);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(true); input[2].setEmit(true); input[3].setEmit(false);
        output(input, output);
        input[0].setEmit(true); input[1].setEmit(true); input[2].setEmit(true); input[3].setEmit(true);
        output(input, output);

    }

    public void output(Perceptron[] a, Perceptron[] b) {
        testOutput(a);
        testOutput(b);
        System.out.println("-------------------------");
    }

    public void testOutput(Perceptron[] output) {
        for (Perceptron i : output) {
            System.out.print(i.emit() + " ");
        }
        System.out.println("");
    }

    public static void main(String[] args) {
        new InformalTest1().nodeTest();
    }

}
